<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>animation tips</title>
    <link rel="stylesheet" href="../../styles/normalize.css" />
    <style type="text/css">
      @keyframes colorchange {
        0% {
          background: yellow;
        }
        100% {
          background: blue;
        }
      }

      .box {
        width: 100px;
        height: 100px;
        border: 1px solid black;
      }

      .changing {
        animation: colorchange 2s;
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
    <div class="runButton">Click me to run the animation</div>

    <script>
      document
        .querySelector(".runButton")
        .addEventListener("click", play, false);
      function play() {
        document.querySelector(".box").className = "box";
        window.requestAnimationFrame(function (time) {
          window.requestAnimationFrame(function (time) {
            document.querySelector(".box").className = "box changing";
          });
        });
      }
    </script>
  </body>
</html>
